package cn.enjoy.tool.base;

import java.lang.reflect.Method;

public class ReflectBridgeMethod {
    public Number get(Number number) {
        System.out.println("parent's method invoke");
        return 1;
    }
}

class Son extends ReflectBridgeMethod {
    // 这里对父类的方法进行了重写，但是返回值类型跟父类中不一样，父类中的返回值类型为Number,子类中的返回值类型为Integer，Integer是Number的子类
    @Override
    public Integer get(Number number) {
        System.out.println("son's method invoke");
        return 2;
    }
}

class PMain {
    public static void main(String[] args) {
        Son son = new Son();
        Method[] declaredMethods = son.getClass().getDeclaredMethods();
        for (int i = 0; i < declaredMethods.length; i++) {
            Method declaredMethod = declaredMethods[i];
            String methodName = declaredMethod.getName();
            Class<?> returnType = declaredMethod.getReturnType();
            Class<?> declaringClass = declaredMethod.getDeclaringClass();
            boolean bridge = declaredMethod.isBridge();
            System.out.print("第" + (i + 1) + "个方法名称：" + methodName + "，方法返回值类型：" + returnType + "  ");
            System.out.print(bridge ? " 是桥接方法" : " 不是桥接方法");
            System.out.println("  这个方法是在" + declaringClass.getSimpleName() + "上申明的");
        }
    }
}

